﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QuanLyThuVien.Business;

namespace QuanLyThuVien.Presentation
{
    public partial class frmThongTinTG : Form
    {
        public frmThongTinTG()
        {
            InitializeComponent();
        }
        TacGiaBUS TGBus = new TacGiaBUS();
        TacGia tg = new TacGia();
        private void frmThongTinTG_Load(object sender, EventArgs e)
        {
            TGBus.LoadLenDG(dgThongTinTG);
        }

        private void btnNhapTG_Click(object sender, EventArgs e)
        {
            try
            {
                tg.MaTG = txtMaTG.Text;
                tg.TenTG = txtTenTG.Text;
                tg.DiaChi = txtxDCTG.Text;
                tg.DienThoai = txtSDT.Text;
                TGBus.ThemMoiTG(tg);
                TGBus.LoadLenDG(dgThongTinTG);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "QuanLyThuVien");
            }
        }

        private void btnTaoMoiTG_Click(object sender, EventArgs e)
        {
            txtMaTG.Text="";
            txtTenTG.Text="";
            txtxDCTG.Text="";
            txtSDT.Text="";
        }

        private void btnSuaTG_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn có thực sự muốn sửa thông tin tác giả hay không?", "QuanLyThuVien", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                tg.MaTG = txtMaTG.Text;
                tg.TenTG = txtTenTG.Text;
                tg.DiaChi = txtxDCTG.Text;
                tg.DienThoai = txtSDT.Text;
                TGBus.SuaTG(tg);
                TGBus.LoadLenDG(dgThongTinTG);
            }
        }

        private void btnXoaTG_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn có thực sự muốn xóa thông tin tác giả hay không?", "QuanLyThuVien", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                TGBus.XoaTG(txtMaTG.Text);
                TGBus.LoadLenDG(dgThongTinTG);
            }
        }

        private void dgThongTinTG_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int a = e.RowIndex;
            txtMaTG.Text=dgThongTinTG[0,a].Value.ToString();
            txtTenTG.Text = dgThongTinTG[1, a].Value.ToString();
            txtxDCTG.Text = dgThongTinTG[2, a].Value.ToString();
            txtSDT.Text = dgThongTinTG[3, a].Value.ToString();
        }
    }
}
